# import requests
# url = 'http://www.douban.com/'
# head = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'}
# response = requests.get(url=url, headers=head)
# response.encoding = response.apparent_encoding
# a = response.text
# print(a)

# import requests
# import json
# url = 'https://fanyi.baidu.com/sug'
# head = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'}
# a = input('请输入文字：')
# data = {'kw': a}
# r = requests.post(url=url, data=data, headers=head)
# b = r.text
# print(json.loads(b))


import requests


def get_html(url, time=10):
    head = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'}
    try:
        r = requests.get(url, headers=head, timeout=time)
        r.encoding = r.apparent_encoding
        r.raise_for_status()
        return r.text
    except Exception as error:
        print(error)


if __name__ == '__main__':
    url = 'http://www.baidu.com'
    print(get_html(url))
